<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>不邻接植花</title>
</head>
<body>
  <script>
    function fn(n, paths) {
      let adjs = new Array(n).fill(null).map(() => [])
      for (let path of paths) {
        adjs[path[0] - 1].push(path[1] - 1)
        adjs[path[1] - 1].push(path[0] - 1)
      }
      let ans = new Array(n).fill(0)
      for (let i = 0; i < n; i++) {
        let adj = adjs[i]
        let arr = []
        for (let j = 0; j < adj.length; j++) {
          arr.push(ans[adj[j]])
        }
        let unused = [1, 2, 3, 4].filter(i => !arr.includes(i))
        ans[i] = unused[0]
      }
      return ans
    }
    console.log(fn(3, [[1, 2], [2, 3], [3, 1]]))
  </script>
</body>
</html>